package com.sikaryofficial.backend.service.points;

import com.sikaryofficial.backend.service.IPointsDetailStrategy;
import com.sikaryofficial.common.core.constant.PointRuleConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author : qinjinyuan
 * @desc : 扫描注册积分服务
 * @date : 2023/10/31 18:58
 */
@Service(value = PointRuleConstant.SCAN_REGISTER + IPointsDetailStrategy.SUFFIX)
@Slf4j
public class ScanRegisterPointsService extends AbstractPointService {
    /**
     * 更新积分明细数据
     *
     * @param sourceId
     * @param userId
     * @param pointsDetailValue
     * @return
     */
    @Override
    public boolean updatePointsByInputValue(Long sourceId, Long userId, Integer pointsDetailValue, String param, String sourceName) {
        boolean isOver = checkEnable(PointRuleConstant.SCAN_REGISTER);
        if (isOver) {
            log.info("SCAN_REGISTER 被禁用");
            return false;
        }
        // 判定是否有积分值的传递，如果没有，则按照正常配置来
        if (Objects.isNull(pointsDetailValue)) {
            return this.increasePoints(sourceId, userId, PointRuleConstant.SCAN_REGISTER, sourceName);
        } else {
            return this.increasePoints(sourceId, userId, PointRuleConstant.SCAN_REGISTER, pointsDetailValue, sourceName);
        }
    }
}
